<%@ page import="agentFree2.*, java.net.*,
 java.io.IOException,
 java.util.Date,
 java.util.logging.Logger,
 javax.jdo.PersistenceManager,
 javax.servlet.http.*,
 javax.jdo.Query,java.net.*,
 java.util.List" %>

<html>
<head>Find agent</head>
<body>
<form action="find.jsp" method="get">
	<input id="searchAgentNumber" name="searchAgentNumber" value=""/>
	<input type="submit" value="Find">
</form>
</body>
</html>
<%

	String searchAgentNumber = "";
	searchAgentNumber = request.getParameter("searchAgentNumber");

	String stringPhoneNumber;
	if (!"".equalsIgnoreCase(searchAgentNumber))
	{

		PersistenceManager pm = PMF.get().getPersistenceManager();
		Query query = pm.newQuery(Agent.class);
	 	 // Query query = pm.newQuery("select from Agent.class " + "where phoneNumber == '172034896'");
	 	 
	    try {
	        List<Agent> results = (List<Agent>) query.execute("Smith");
	        if (!results.isEmpty()) {
	            for (Agent e : results) {
	            	stringPhoneNumber = e.getPhoneNumber().toString();
	                if (stringPhoneNumber.matches(".*"+searchAgentNumber+".*"))
	                out.println(stringPhoneNumber+"       "+e.getAgentName()+"       "+e.getUrl());
	            }
	        } else {
	            // ... no results ...
	        }
	    } finally {
	        query.closeAll();
	    }
	}
%>